package com.huaxin.hxmoduleworkorder.mapping;

import com.huaxin.hxmoduleworkorder.common.enums.MaintenanceOrderElectricianTaskStatus;
import com.huaxin.hxmoduleworkorder.dto.request.MaintenanceOrderElectricianTaskCreateReqDTO;
import com.huaxin.hxmoduleworkorder.models.MaintenanceOrderElectricianTask;
import org.mapstruct.AfterMapping;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingTarget;

import java.time.LocalDateTime;
import java.util.List;

@Mapper(componentModel = "spring")
public interface MaintenanceOrderElectricianTaskMapping {
    @Mapping(target = "assignAt", ignore = true)
    @Mapping(target = "acceptAt", ignore = true)
    @Mapping(target = "rejectAt", ignore = true)
    @Mapping(target = "rejectReason", ignore = true)
    @Mapping(target = "onSiteAt", ignore = true)
    @Mapping(target = "resolveAt", ignore = true)
    @Mapping(target = "status", ignore = true)
    MaintenanceOrderElectricianTask toEntity(MaintenanceOrderElectricianTaskCreateReqDTO in);

    @AfterMapping
    default void afterMapping(MaintenanceOrderElectricianTaskCreateReqDTO dto, @MappingTarget MaintenanceOrderElectricianTask entity) {
        entity.setStatus(MaintenanceOrderElectricianTaskStatus.ASSIGNED);
        entity.setAssignAt(LocalDateTime.now());
    }

    @Mapping(source = "status", target = "status", ignore = true)
    List<MaintenanceOrderElectricianTask> toEntityList(List<MaintenanceOrderElectricianTaskCreateReqDTO> in);
}